#include "PrecompiledHeader.h"
#include "Variable.h"

/*--------------------------------------------------------------------------*/

Variable::Variable(const std::string& name) :
	m_name(name),
	m_strValue("undefined"),
	m_intValue(-1),
	m_fltValue(-1.0f)
{

}

/*--------------------------------------------------------------------------*/

Variable::Variable(const std::string& name, const std::string& s) :
	m_name(name)
{
	this->Set(s);
}

/*--------------------------------------------------------------------------*/

Variable::Variable(const std::string& name, int i) :
	m_name(name)
{
	this->Set(i);
}

/*--------------------------------------------------------------------------*/

Variable::Variable(const std::string& name, float d) :
	m_name(name)
{
	this->Set(d);
}

/*--------------------------------------------------------------------------*/

Variable::Variable(const std::string& name, bool b) :
	m_name(name)
{
	this->Set(b);
}


/*--------------------------------------------------------------------------*/

Variable::~Variable()
{

}

/*--------------------------------------------------------------------------*/

void Variable::Set(const std::string& s)
{
	this->m_strValue = s;
	std::stringstream ss;
	ss << s;
	ss >> this->m_fltValue;
	this->m_intValue = (int) this->m_fltValue;
}

/*--------------------------------------------------------------------------*/

void Variable::Set(int i)
{
	std::stringstream ss;
	ss << i;
	this->m_strValue = ss.str();
	this->m_intValue = i;
	this->m_fltValue = (float) i;
}

/*--------------------------------------------------------------------------*/

void Variable::Set(float d)
{
	std::stringstream ss;
	ss << d;
	this->m_strValue = ss.str();
	this->m_intValue = (int) d;
	this->m_fltValue = d;
}

/*--------------------------------------------------------------------------*/

void Variable::Set(bool b)
{
	if (b)
	{
		this->m_strValue = "true";
		this->m_fltValue = 1.0f;
		this->m_intValue = 1;
	}
	else
	{
		this->m_strValue = "false";
		this->m_fltValue = 0.0f;
		this->m_intValue = 0;
	}
}

/*--------------------------------------------------------------------------*/

int Variable::GetInt() const
{
	return this->m_intValue;
}

/*--------------------------------------------------------------------------*/

float Variable::GetFloat() const
{
	return this->m_fltValue;
}

/*--------------------------------------------------------------------------*/

const std::string& Variable::GetString() const
{
	return this->m_strValue;
}

/*--------------------------------------------------------------------------*/

bool Variable::GetBool() const
{
	return this->m_intValue != 0;
}

/*--------------------------------------------------------------------------*/

const std::string& Variable::GetName() const
{
	return this->m_name;
}

/*--------------------------------------------------------------------------*/